home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 8 / Mac Magazin and MacEasy Magazine CD - Issue 08.iso / Sharewarebibliothek / Utilities / Minimalist Clock 1.0 / src / clock.c < prev    next >
Text File  |  1994-12-07  |  2KB  |  60 lines

  1. /* ----------------------------------------------------------------------
  2. clock.c
  3. ---------------------------------------------------------------------- */
  4.  
  5. #include    "the_defines.h"
  6. #include    "the_globals.h"
  7. #include    "the_prototypes.h"
  8.  
  9.  
  10. /* ----------------------------------------------------------------------
  11. CreateClock
  12. ---------------------------------------------------------------------- */
  13. void CreateClock()
  14. {
  15.     WindowRecord    *clockWinRec;
  16.     Rect            myWinRect;
  17.     Str255             myTitle;
  18.  
  19.     myWinRect = qd.screenBits.bounds;
  20.     myWinRect.left = myWinRect.right - (CLOCK_WIDTH + 20);
  21.     myWinRect.right = myWinRect.left + CLOCK_WIDTH;
  22.     myWinRect.top = myWinRect.top + 40;
  23.     myWinRect.bottom = myWinRect.top - 1;
  24.     
  25.     clockWinRec = NIL;
  26.     gClock = NewWindow(clockWinRec,&myWinRect,"\p ",FALSE,4,(WindowPtr)-1L,FALSE,0L);
  27.     
  28.     UpdateClock();
  29.     ShowWindow(gClock);
  30. }
  31.  
  32. /* ----------------------------------------------------------------------
  33. UpdateClock
  34. ---------------------------------------------------------------------- */
  35. void UpdateClock()
  36. {
  37.     unsigned long    rawTime;
  38.     DateTimeRec        theDate;
  39.     Str255            theNewTime,theOldTime;
  40.     Intl0Hndl        iOh = GetIntlResource(0);
  41.     GrafPtr            savedPort;
  42.  
  43.     GetDateTime(&rawTime);
  44.     if (gDrawDate)
  45.     {
  46.         IUDatePString(rawTime,0,theNewTime,(Handle)iOh);
  47.         gTicksOld = TickCount();
  48.     }
  49.     else
  50.         IUTimePString(rawTime,FALSE,theNewTime,(Handle)iOh);
  51.  
  52.     GetPort(&savedPort);
  53.     SetPort(gClock);
  54.     GetWTitle(gClock,theOldTime);
  55.     if (!EqualString(theOldTime,theNewTime,FALSE,FALSE) || gDrawDate)
  56.         SetWTitle(gClock,theNewTime);
  57.     SetPort(savedPort);
  58.     gDrawDate = gDrawDate && FALSE;
  59. }
  60.